Skip to content

Add tokenpath parameter to collector #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 9, 2025
Merged

Add tokenpath parameter to collector #1077

merged 11 commits into from
Jun 9, 2025

Conversation

john-david3
Copy link
Contributor

Proposed changes

  • Add tokenpath parameter to collecter
  • Collector now accepts a tokenpath as the value in the header-setter parameter of the agent config
  • Add unit test for resolveExtensions method

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • I have run make install-tools and have attached any dependency changes to this pull request
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes
  • If applicable, I have updated any relevant documentation (README.md)
  • If applicable, I have tested my cross-platform changes on Ubuntu 22, Redhat 8, SUSE 15 and FreeBSD 13

@john-david3 john-david3 self-assigned this May 14, 2025
@john-david3 john-david3 requested a review from a team as a code owner May 14, 2025 12:46
@github-actions github-actions bot added the chore Pull requests for routine tasks label May 14, 2025
@john-david3 john-david3 added the v3.x Issues and Pull Requests related to the major version v3 label May 14, 2025
//go:embed testdata/nginx-agent-with-token.conf
var agentConfigWithToken string

func getAgentConfigWithToken(token string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be moved to /agent/test/config/nginx_config.go

@@ -871,6 +871,7 @@ func processOtlpReceivers(tlsConfig *OtlpTLSConfig) error {
func resolveExtensions() Extensions {
var health *Health
var headersSetter *HeadersSetter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a new FilePath field to the Header struct instead of putting file paths in the Value field.

if headersSetter != nil {
token, err := getToken(headersSetter)
if err != nil {
slog.Error("error getting token from config", "error", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
slog.Error("error getting token from config", "error", err)
slog.Error("Unable to get token from collector headers setter config", "error", err)

func getToken(headersSetter *HeadersSetter) (string, error) {
var err error

token := headersSetter.Headers[0].Value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to handle the case where there are more than one header so you will need to loop through the list and check the Value and FilePath for each one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are multiple, which one do we use?

return Extensions{
Health: health,
HeadersSetter: headersSetter,
}
}

func values(headers []Header) []Header {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the function to something like updateHeaders?

@john-david3 john-david3 merged commit 16ab50e into main Jun 9, 2025
23 checks passed
@john-david3 john-david3 deleted the collector-tokenpath branch June 9, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Pull requests for routine tasks v3.x Issues and Pull Requests related to the major version v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants